﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.DAO;
using ERP_RORZE_DLL.Product.database;
using ERP_RORZE_PERMISSION.Base;

namespace ERP_RORZE_PRODUCT.Product.BasicList
{
    public partial class ctrlSection : DevExpress.XtraEditors.XtraUserControl
    {
        ClsBasicListDAO clsBasiclistDAO = new ClsBasicListDAO();
        DataTable dt;
        private LogUtils log;
        Section b = new Section();
        public ctrlSection()
        {
            InitializeComponent();
            log = new LogUtils();
        }
        void Reload(object sender, EventArgs e)
        {
            dt = clsBasiclistDAO.GetAllSection();
            gridControl1.DataSource = dt;
        }
        private void ctrlSection_Load(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            frm_SectionAdd frmAdd = new frm_SectionAdd();
            frmAdd.Text = "Nhập mới";
            frmAdd.Reload += new EventHandler(Reload);
            frmAdd.ShowDialog();
        }

        private void btnReload_Click(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            frm_SectionEdit frmEdit = new frm_SectionEdit();
            frmEdit.SectionID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SectionID").ToString();
            frmEdit.SectionName = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SectionName").ToString();
            frmEdit.Text = "Sửa thông tin ";
            frmEdit.Reload += new EventHandler(Reload);
            frmEdit.ShowDialog();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            b.SectionID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SectionID").ToString();
            clsBasiclistDAO.DeleteSection(b);

            //write Log
            log.Table = LogConstant.Table.Product.Section;
            log.Task = LogConstant.Task.Delete;
            log.Description = b.SectionID;
            log.WriteLog();

            Reload(sender, e);
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnAddNew_Click(object sender, EventArgs e)
        {
            btnAdd_Click(sender, e);
        }

        private void btEdit_Click(object sender, EventArgs e)
        {
            btnEdit_Click(sender, e);
        }

        private void btDelete_Click(object sender, EventArgs e)
        {
            btnDelete_Click(sender, e);
        }

    }
}
